package cn.wit.job.controller;

import cn.wit.job.condition.SearchSkillsCondition;
import cn.wit.utils.pojo.Skills;
import cn.wit.job.service.SkillsService;
import cn.wit.utils.response.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/job/skills")
@CrossOrigin
@Api(tags = "面经")
public class SkillsController {
    private Logger logger = LoggerFactory.getLogger(SkillsController.class);

    @Autowired
    private SkillsService skillsService;

    @PostMapping("/insertSkills")
    @ApiOperation("新增面经")
    public Result insertSkills(@RequestBody Skills skills) {
        return this.skillsService.insert(skills);

    }

    @PutMapping("/deleteSkills/{id}")
    @ApiOperation("删除面经")
    public Result deleteSkills(@PathVariable("id") int id) {
        return this.skillsService.deleteById(id);
    }

    @PutMapping("/updateSkills")
    @ApiOperation("更新面经")
    public Result updateSkills(@RequestBody Skills skills) {
        return this.skillsService.updateById(skills);

    }


    @GetMapping("/searchSkills/{num}/{size}")
    @ApiOperation("分页条件查询所有面经")
    public Result searchSkills(@PathVariable("num") int num,
                               @PathVariable("size") int size,SearchSkillsCondition condition) {
        IPage<Skills> page = new Page<>(num, size);
        return this.skillsService.searchPage(page, condition);
    }
}
